﻿<!-- Dash board index screen-->
﻿<link rel="stylesheet" type="text/css" href="~/Content/dashboardstyle/dashboardstyle.css" />

@{
    int DEFAULT_WIDTH = 750;
    int DEFAULT_HEIGH = 150;
    string color = "";
    string bold = "";
    float scale_level; 
}
@model IEnumerable<Vms.Web.Models.SCREEN>
@{
    ViewBag.Title = "Index";
    Vms.Web.Models.PROGRAM curProgram;
    int i = 0;
}
<h2>
    VMS Screens system</h2>
<div id="wrap">
    <ul id="container"> 
        @{if( Model.Count() ==0 ){
              <p class="notify">There's no screen to display!  </p>
          }}
        @foreach (var item in Model)
        {

            //scale screen according to the max size
            float scr_heigh = (float)item.Height;
            float scr_width = (float)item.Width;
            float max_size = ((scr_heigh * DEFAULT_WIDTH) > (scr_width * DEFAULT_HEIGH)) ? scr_heigh : scr_width;
            if (max_size == scr_heigh)
            {
                scale_level = DEFAULT_HEIGH / scr_heigh;
                scr_width = (scr_width * DEFAULT_HEIGH) / scr_heigh;
                scr_heigh = DEFAULT_HEIGH;
            }
            else
            {
                scale_level = DEFAULT_WIDTH / scr_width;
                scr_heigh = (scr_heigh * DEFAULT_WIDTH) / scr_width;
                scr_width = DEFAULT_WIDTH;
            }

            float imgHeight = 0;
            float imgWidth = 0;
            float imgTop = 0, imgLeft = 0;
            float textWidth = 0, textHeight = 0, textTop = 0, textLeft = 0;
            // content displayed in the screen
            Vms.Web.Models.CONTENT_IMG content_img = new Vms.Web.Models.CONTENT_IMG();
            Vms.Web.Models.CONTENT_TXT content_txt = new Vms.Web.Models.CONTENT_TXT();

            //if (item.PROGRAMS.Count() != 0) // if there's program displaying in the screen
            //{
            //    curProgram = item.PROGRAMS.First();//Single(p => p.Id == item.ScreenStatus.CurrentProgram_Id);
            //    if (curProgram.CONTENTS != null)
            //    {
            //        content_img = curProgram.CONTENTS.First().CONTENT_IMG.First();
            //        if (curProgram.CONTENTS.First().CONTENT_TXT != null)
            //        {
            //            content_txt = curProgram.CONTENTS.First().CONTENT_TXT.First();
            //        }
            //        bold = (content_txt.Bold == null || (bool)content_txt.Bold == false) ? "" : "font-weight:Bold;";
            //        if (content_img != null)
            //        {
            //            imgHeight *= scale_level;
            //            imgWidth *= scale_level;
            //            imgTop = scale_level * (content_img.Img_y.ToString().AsFloat());
            //            imgLeft = scale_level * (content_img.Img_x.ToString().AsFloat());
            //        }
            //        if (content_txt != null)
            //        {
            //            textHeight = scale_level * content_txt.Txt_Height.ToString().AsFloat();
            //            textWidth = scale_level * content_txt.Txt_Width.ToString().AsFloat();
            //            textTop = scale_level * content_txt.Txt_y.ToString().AsFloat();
            //            textLeft = scale_level * content_txt.Txt_x.ToString().AsFloat();
            //        }
            //        switch (content_txt.FontColor)
            //        {
            //            case 0:
            //                color = "Black";
            //                break;
            //            case 1:
            //                color = "Red";
            //                break;
            //            case 2:
            //                color = "Green";
            //                break;
            //            case 3:
            //                color = "Yellow";
            //                break;
            //            case 4:
            //                color = "Blue";
            //                break;
            //            case 5:
            //                color = "Mauve";
            //                break;
            //            case 6:
            //                color = "LightGreen";
            //                break;
            //            case 7:
            //                color = "White";
            //                break;

            //        }
            //    }

                String status = @item.ScreenStatus.OnOff == 1 ? "On" : "Off";
            <li>
                <div class="screen-1">
                    <div class="bound">
                        <div class="dashboard" style="width:  @{@scr_width}px; height: @{@scr_heigh}px; ">
                            <img alt="" width="@imgWidth" height="@imgHeight" style="top:@{@imgTop}px; left:@{@imgLeft}px; position: absolute ;" src="../../Areas/Lib/Lib_Data/Imgs/@content_img.ImgFileName" />
                            @* <label style="@bold top:@{@textTop}px; left:@{@textLeft}px; position: absolute ; width:@{@textWidth}px; height:@{@textHeight}px; color:@color; font-size:@{@content_txt.FontSize}px; font-family:@{@content_txt.FontName}; " >
                               @content_txt.Txt
                            </label>*@
                            <label style="@bold top:@{@textTop}px; left:@{@textLeft}px; color:@color; font-size:@{@content_txt.FontSize}px; font-family:@{@content_txt.FontName}; " >
                                @content_txt.Txt
                            </label>
                        </div>
                    </div>
                    <div class="src-info">
                        <ul>
                            <li><a href="#">Screen @i:<span> @item.Name</span></a></li>
                            <li><a href=@Url.Action("SendProgramToScreen", "Dashboard", new { screenId = item.Id }) style="color:Orange">
                                Send Program</a></li>
                            <li>
                             
                                </li>
                                <li><a href=@Url.Action("Index", "ContentProgram", new { screenId = item.Id })>View
                                    program</a></li>
                                <li class="status">Status: 
                                <span>@status</span>
                                
                                </li>
                                <li>
                                <div class = "onoff">
                                  
                                    <a href=@Url.Action("TurnOnScreen", "Dashboard", new { screenId = item.Id, isOn = 0 }) style="color:Blue" class="btn btn-danger">
                                        Turn Off</a>
                                  
                                            
                                    <a href=@Url.Action("TurnOnScreen", "Dashboard", new { screenId = item.Id, isOn = 1 }) class="btn btn-success btn-small" style="color:Green">
                                        Turn On</a>                        
                                </div>
                                </li>
                        </ul>
                    </div>
                </div>
            </li>
            
        }
    </ul>
</div>
